package io.github.wslxm.springbootplus2.starter.websocket.topic;

import com.alibaba.fastjson.JSON;
import io.github.wslxm.springbootplus2.starter.websocket.model.vo.SendMsgVO;
import io.github.wslxm.springbootplus2.starter.websocket.server.OpenWebSocketApi;
import io.github.wslxm.springbootplus2.starter.websocket.server.WebsocketServer;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;

/**
 * 订阅者
 *@author wangsong
 * @date 2023/05/17
 */
@Component
public class WebsocketMsgListener implements MessageListener {


    @Override
    public void onMessage(Message message, byte[] pattern) {
        String messageStr = new String(message.getBody());
        SendMsgVO sendMsgVO = JSON.parseObject(messageStr, SendMsgVO.class);
        // 发送消息
        OpenWebSocketApi.send(sendMsgVO);
    }
}

